package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.TravelBean;
import com.scoy.honeymei.utils.GlideImgUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class TravelAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<TravelBean> datalist;
    private TextView notv;
    private int type;

    public TravelAdapter(Context context, ArrayList<TravelBean> datalist, TextView notv) {
        this.context = context;
        this.datalist = datalist;
        this.notv = notv;
    }

    public TravelAdapter(Context context, ArrayList<TravelBean> datalist, int type) {
        this.context = context;
        this.datalist = datalist;
        this.type = type;
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_travel, parent, false);
        return new TravelHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        TravelHolder travelHolder = (TravelHolder) holder;
        TravelBean travelBean = datalist.get(position);
        GlideImgUtil.glidePic(context, travelBean.getImage(), travelHolder.itlImgIv,10);
        travelHolder.itlNameTv.setText(travelBean.getName());
        travelHolder.itlTraveltypeTv.setText(travelBean.getType_name());
        travelHolder.itlTravelpriceTv.setText(travelBean.getPrice());


        travelHolder.itemTravel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onOneClick != null) {
                    onOneClick.oneClick(position);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        int iCount = datalist == null ? 0 : datalist.size();
        if(type!=1){
            if (iCount == 0) {
                notv.setVisibility(View.VISIBLE);
            } else {
                notv.setVisibility(View.GONE);
            }
        }
        return iCount;
    }


    class TravelHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.itl_img_iv)
        ImageView itlImgIv;
        @BindView(R.id.itl_name_tv)
        TextView itlNameTv;
        @BindView(R.id.itl_traveltype_add_tv)
        TextView itlTraveltypeAddTv;
        @BindView(R.id.itl_traveltype_tv)
        TextView itlTraveltypeTv;
        @BindView(R.id.itl_travelpriceadd_tv)
        TextView itlTravelpriceaddTv;
        @BindView(R.id.itl_travelprice_tv)
        TextView itlTravelpriceTv;
        @BindView(R.id.item_travel)
        LinearLayout itemTravel;

        TravelHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
